import React, { useState, useEffect } from 'react'
import { getDetail, delService, print, confirmSend } from './utils'
import NormalBtns from './components/NormalBtns'
import OtherBtns from './components/OtherBtns'
import ArbitratorBtns from './components/ArbitratorBtns'

function Main ({ data = {}, theme = {}, caseDetail = {}, editable, pDispatch = () => {}, common, refreshTable = () => {} }) {
  const { type } = theme
  const [utils, setUtils] = useState(null)
  useEffect(() => {
    const id = data.id
    setUtils({
      detailfn: getDetail.bind(this, id, pDispatch, refreshTable),
      delFn: delService.bind(this, id, refreshTable),
      printFn: print.bind(this, common, id, caseDetail.id, theme, refreshTable),
      confirmSend: confirmSend.bind(this, id, pDispatch, refreshTable)
    })
  }, [caseDetail.id, common, data.id, pDispatch, refreshTable, theme])
  let Btns = NormalBtns
  if (type === '自定义送达') {
    Btns = OtherBtns
  } else if (type === '仲裁员送达') {
    Btns = ArbitratorBtns
  }
  return (
    <Btns data={data} theme={theme} editable={editable} utils={utils} />
  )
}

export default Main
